#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

int main(int argc, char *argv[])
{
  int rank, i, j, k = 1;
  int **cell, *row1, *cellblock;
  MPI_Status status;
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  row1 = (int*)calloc((5+1) * 2, sizeof(int));
  cellblock = (int*)calloc((4+1)*(5+1), sizeof(int));
  cell = &cellblock;
  for (i = 0 ; i < (4+1) ; i++)
    cell[i] = &cellblock[i*(5+1)];
  if (rank == 0)
    {
      for (i = 0 ; i < (4+1) ; i++)
        for (j = 0 ; j < (5+1) ; j++)
          cell[i][j] = k++;
      for (i = 1 ; i < 5 ; i+=2)
        MPI_Send(&(cell[i][0]), (5+1)*2, MPI_INT, 1, 1, MPI_COMM_WORLD);
    }
  if (rank == 1)
    {
      for (i = 0 ; i < 2 ; i++)
        {
          MPI_Recv(row1, (5+1)*2, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
          for (j = 0 ; j < (5+1)*2 ; j++)
            printf("%d ", row1[j]);
          printf("\n");
        }
    }
  free(row1);
  free(cellblock);
  MPI_Finalize();
  return 0;
}
